﻿using System;

namespace NUnit.Framework
{
    public static class ExceptionAssertions
    {
        public static void ShouldContainErrorMessage(this Exception exception, string expected)
        {
            exception.Message.ShouldContain(expected);
        }

        public static Exception ShouldBeThrownBy(this Type exceptionType, Action action)
        {
            Exception exception = null;

            try
            {
                action();
            }
            catch (Exception e)
            {
                Assert.AreEqual(exceptionType, e.GetType());
                exception = e;
            }

            if (exception == null)
            {
                Assert.Fail(String.Format("Expected {0} to be thrown.", exceptionType.FullName));
            }

            return exception;
        }

    }
}